using System.ComponentModel.DataAnnotations;
using FytSoa.Common.Enum;
using FytSoa.Domain.Hr;
using SqlSugar;

namespace FytSoa.Domain.Crm;

/// <summary>
/// 项目管理
/// </summary>
[SugarTable("crm_project")]
public class CrmProject:Entity
{
    /// <summary>
    /// 项目编号
    /// </summary>
    [Required]
    [StringLength(50)]
    public string Number { get; set; }
    
    /// <summary>
    /// 项目名称
    /// </summary>
    [Required]
    [StringLength(255)]
    public string Name { get; set; }

    /// <summary>
    /// 项目类型
    /// </summary>
    public CrmProjectTypeEnum ProjectType { get; set; } = CrmProjectTypeEnum.Opportunity;

    /// <summary>
    /// 客户编号
    /// </summary>
    [Required]
    public long CustomerId { get; set; }
    
    /// <summary>
    /// 所属客户
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(CustomerId))]
    public CrmCustomer Customer { get; set; }

    /// <summary>
    /// 联系人编号，多个
    /// </summary>
    [Required]
    public long ContactId { get; set; } = 0;
    
    /// <summary>
    /// 客户联系人
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ContactId))]
    public CrmContact Contact { get; set; }

    /// <summary>
    /// 负责人编号
    /// </summary>
    [Required]
    public long ManagerEmployeeId { get; set; }
    
    /// <summary>
    /// 负责人
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ManagerEmployeeId))]
    public HrEmployee ManagerEmployee { get; set; }

    /// <summary>
    /// 其他成员
    /// </summary>
    [Required]
    [SugarColumn(IsJson = true)]
    public List<OtherEmployeeJson> OtherEmployee { get; set; } = new();

    /// <summary>
    /// 项目状态  0=未开始 1=进行中 2=已完成 3=已关闭
    /// </summary>
    [Required]
    public CrmProjectStatusEnum Status { get; set; } = 0;
    
    /// <summary>
    /// 商机状态
    /// </summary>
    [Required]
    public CrmOpportunityStatusEnum OpportunityStatus { get; set; } = 0;

    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 关联合同
    /// </summary>
    [SugarColumn(IsJson = true)]
    public List<long> ByContract { get; set; } = new();

    /// <summary>
    /// 涉及金额
    /// </summary>
    [Required]
    public decimal Amount { get; set; }

    /// <summary>
    /// 折扣
    /// </summary>
    [Required]
    public int Discount { get; set; } = 0;
    
    /// <summary>
    /// 成交率
    /// </summary>
    [Required]
    public int ClosureRate { get; set; } = 0;

    /// <summary>
    /// 附件
    /// </summary>
    [SugarColumn(IsJson = true)]
    public List<FileBase> Files { get; set; } = new();

    /// <summary>
    /// 项目简介
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string CreateUser { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Required]
    public DateTime CreateTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 更新人
    /// </summary>
    public string UpdateUser { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 其他成员信息
    /// </summary>
    public class OtherEmployeeJson
    {
        /// <summary>
        /// 用户编号
        /// </summary>
        public long Id { get; set; }
        
        public string Letter { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }
    }
}